
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no,width=device-width">
    <meta name="format-detection" content="telephone=yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <title>测试支付</title>
    <link href="/css/csscss?v=0" rel="stylesheet" type="text/css">
</head>

<body>
<div class="index_box">
    <div class="apply_name">微信js支付测试</div>


    <div class="branch_con">
        <ul>
            <li><span class="name">测试支付信息</span></li>
        </ul>
        <p class="cz_btn"><a href="javascript:pay();" class="btn_1">立即支付</a></p>
    </div>
</div>

<script type="text/javascript" src="/js/zeptominjs"></script>
<script type="text/javascript" src="/js/commonjs"></script>
<script type="text/javascript">
    function onBridgeReady(){
//获取appId、timeStamp、nonceStr、package、signType、paySign
        var addrip = "<%=addrip%>";
        var userid = "<%=user%>";
        var appId;
        var timeStamp;
        var nonceStr;
        var signType;
        var packAge;
        var paySign;
        $.post('/weixin/cj/Cjaction!getParameter.action',{addrip:addrip,userid:userid},function(data)
        {
            var brandWCPayParameter =data[0];
            appId = brandWCPayParameter.appId;
            timeStamp = brandWCPayParameter.timeStamp;
            nonceStr = brandWCPayParameter.nonceStr;
            signType = brandWCPayParameter.signType;
            packAge = brandWCPayParameter.packAge;
            paySign = brandWCPayParameter.paySign;
            alert(paySign);
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest', {
                    "appId" : appId,     //公众号名称，由商户传入
                    "timeStamp": timeStamp,         //时间戳，自1970年以来的秒数
                    "nonceStr" : nonceStr, //随机串
                    "package" : packAge,
                    "signType" : signType,         //微信签名方式:
                    "paySign" : paySign    //微信签名
                },

                function(res){
                    if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                        alert("支付成功");
                    }
                }
            );
        },"json");
    }
    function pay(){
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }else{
            onBridgeReady();
        }
    }

</script>
</body>
</html>
